<?php
/**
 * QuestionFeedbacksController.php
 *
 * @copyright   2023 thingsworld.com.cn - All Rights Reserved
 * @link        http://thingsworld.com.cn/
 * @author      stiffer.chen <chenl@thingsworld.com.cn>
 * @created     2023-08-05 11:39:55
 * @modified    2023-08-05 11:39:55
 *
 */

namespace App\Http\Controllers;

use App\Models\QuestionFeedback;
use App\Repositories\QuestionFeedbackRepo;
use App\Services\DeptService;
use Illuminate\Http\Request;

class QuestionFeedbacksController extends BaseController
{
    // 列表
    public function index(Request $request)
    {
        try {
            $export = intval($request->get('export', 0));
            $data = QuestionFeedbackRepo::getList();
            if ($export) {
                return message('导出成功', true, $data);
            }
            return list_message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 参数
    public function params()
    {
        $data = QuestionFeedbackRepo::params();
        return message('获取成功', true, $data);
    }

    // 详情
    public function show(Request $request, $id)
    {
        try {
            $data = QuestionFeedbackRepo::getDetail($id);
            return message('获取成功', true, $data);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 待处理数量
    // 非区域经理和品质工程师 => 0
    public function un_process_count(Request $request)
    {
        try {
            $count = QuestionFeedbackRepo::unProcessCount();
            return message('获取成功', true, $count, 0, false);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 创建
    public function store(Request $request)
    {
        try {
            $qf = QuestionFeedbackRepo::store();
            return message('提交成功', true, $qf);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 关闭
    public function close(Request $request, $id)
    {
        try {
            $qf = QuestionFeedbackRepo::close($id);
            return message('关闭成功', true, $qf);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 区域经理审核(反馈至品质部)
    public function audit(Request $request, $id)
    {
        try {
            $qf = QuestionFeedbackRepo::audit($id);
            return message('审核成功', true, $qf);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 品质工程师审核
    public function quantity_audit(Request $request, $id)
    {
        try {
            $qf = QuestionFeedbackRepo::quantityAudit($id);
            return message('审核成功', true, $qf);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }

    // 工程师处理
    public function action(Request $request, $id)
    {
        try {
            $qf = QuestionFeedbackRepo::action($id);
            return message('处理成功', true, $qf);
        } catch (\Exception $e) {
            return message($e->getMessage(), false);
        }
    }
}